package com.shengchang.hu.supervision.Utils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

import com.shengchang.hu.supervision.R;

public class CensusAlertDialog   extends Dialog implements View.OnClickListener {

    private Context context;
    private String title;
    private String message;
    private String strPositive;
    private String strNegative;
    private AlertDialog.OnDialogButtonClickListener listener;
    private boolean cancelable = true;

    public CensusAlertDialog(Context context, String title, String message,
                       String strPositive, String strNegative, AlertDialog.OnDialogButtonClickListener listener) {
        super(context, R.style.MyDialog);
        this.context = context;
        this.title = title;
        this.message = message;
        this.strPositive = strPositive;
        this.strNegative = strNegative;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.census_dialog_layout);

        //alertDialog是否可以点击外围消失
        setCanceledOnTouchOutside(cancelable);
        setCancelable(cancelable);



        final WindowManager.LayoutParams params = this.getWindow().getAttributes();
        params.gravity = Gravity.CENTER;
        this.getWindow().setAttributes(params);

    }

    @Override
    public void onClick(final View v) {
        if (v.getId() == R.id.tv_dialog_positive) {
            listener.onDialogButtonClick(true);
        } else if (v.getId() == R.id.tv_dialog_negative) {
            listener.onDialogButtonClick(false);
        }
        dismiss();
    }


    /**
     * 自定义Dialog监听器
     */
    public interface OnDialogButtonClickListener {

        /**
         * 点击按钮事件的回调方法
         *
         * @param isPositive
         */
        void onDialogButtonClick(boolean isPositive);
    }
}
